﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.RoleCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.RoleHandler
{
    public class FanRoleHandler : IRequestHandler<FanRoleCommand, APIResult<List<Role>>>
    {
        private readonly IBaseRepository<Role> roleRep;

        public FanRoleHandler(IBaseRepository<Role> roleRep)
        {
            this.roleRep = roleRep;
        }

        public Task<APIResult<List<Role>>> Handle(FanRoleCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Role>> result = new APIResult<List<Role>>();
            try
            {
                var model = roleRep.GetAll().Where(x=>x.RoleId==request.RoleId).ToList();
                result.Code = APIEnum.Success;
                result.Msg = "查询单挑数据成功";
                result.Data = model;
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
